#include <bits/stdc++.h>

using namespace std;

const int N = 25;

int a[N];

int n;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);
    //cout << (&en - &st) / 1024.0 / 1024 << '\n';
    int tt;
    cin >> tt;
    while (tt--) {
        cin >> n;
        for (int i = 0; i < n; i++) {
            cin >> a[i];
        }
        int res = 0;
        for (int i = 0; i < (1 << n); i++) {
            int red = 0, blue = 0;
            int ans = 0;
            for (int j = 0; j < n; j++) {
                if ((i >> j) & 1) {
                    ans += (a[j] == red) * a[j];
                    red = a[j];
                } else {
                    ans += (a[j] == blue) * a[j];
                    blue = a[j];
                }
            }
            res = max(res, ans);
        }
        cout << res << '\n';
    }
    return 0;
}
